/**
 * Copyright (c) 2006 RiseSoft Co.,Ltd  
 * $Header$
 */
package cn.newtest.bi.collection.model;

import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;

/**
 * 专业
 *
 * @author <a href="mailto: chenjian@risesoft.net">陈健</a>
 * @version $Revision$
 * 
 */
@Entity
@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name="Rpt_Speciality")
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class Speciality implements Comparable<Object>, Serializable {
	
	private static final long serialVersionUID = 3612242642711073669L;

	@Id
	@Column(name="Speciality_GUID",length=38)
	@GenericGenerator(name="Speciality-assigned",strategy="assigned")
	private String guid;
	
	@Column(name="Speciality_Name",length=40,nullable=false)
	private String name;
	
	@Column(name="Speciality_ChineseName",length=128)
	private String chineseName;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="Service_Guid")
	private Service service;
	
	@Basic
	private Double tabIndex;
	
	@Column(name="Speciality_Description",length=500)
	private String description;
	
	@Transient
	public String getServiceGuid() {
		if(service != null){
			return service.getGuid();
		}
		return "";
	}
	public void setServiceGuid(String serviceGuid) {
		if(serviceGuid != null && serviceGuid.trim().length()>0){
			if(service==null){
				service = new Service();				
			}
			service.setGuid(serviceGuid);			
		}
	}
	
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getChineseName() {
		return chineseName;
	}

	public void setChineseName(String chineseName) {
		this.chineseName = chineseName;
	}

	public String getGuid() {
		return guid;
	}

	public void setGuid(String guid) {
		this.guid = guid;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Double getTabIndex() {
		return tabIndex;
	}

	public void setTabIndex(Double tabIndex) {
		this.tabIndex = tabIndex;
	}

	public Service getService() {
		return service;
	}

	public void setService(Service service) {
		this.service = service;
	}

	/**
	 * @see java.lang.Comparable#compareTo(Object)
	 */
	public int compareTo(Object object) {
		Speciality myClass = (Speciality) object;
		return new CompareToBuilder().append(this.description, myClass.description).append(this.chineseName, myClass.chineseName).append(this.guid, myClass.guid).append(this.tabIndex, myClass.tabIndex)
				.append(this.name, myClass.name).toComparison();
	}

	/**
	 * @see java.lang.Object#equals(Object)
	 */
	public boolean equals(Object object) {
		if (!(object instanceof Speciality)) {
			return false;
		}
		Speciality rhs = (Speciality) object;
		return new EqualsBuilder().appendSuper(super.equals(object)).append(this.description, rhs.description).append(this.chineseName, rhs.chineseName).append(this.guid, rhs.guid)
				.append(this.tabIndex, rhs.tabIndex).append(this.name, rhs.name).isEquals();
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return new HashCodeBuilder(1181584419, -397103033).appendSuper(super.hashCode()).append(this.description).append(this.chineseName).append(this.guid).append(this.tabIndex).append(this.name).toHashCode();
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return new ToStringBuilder(this).append("tabIndex", this.tabIndex).append("name", this.name).append("chineseName", this.chineseName).append("description", this.description).append("guid", this.guid).toString();
	}
}